package src.application.Doppelkopf;

import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

/**
 * Thread fuer Clients (vom Server)
 * @author b.osterholt
 */
public class Connection extends Thread{
    DataInputStream in; DataOutputStream out;
    Socket clientSocket;
    private int nr;
    
    public Connection (Socket aClientSocket, int aNr){
        try {
            clientSocket = aClientSocket;
            out = new DataOutputStream(clientSocket.getOutputStream());
            in = new DataInputStream(clientSocket.getInputStream());
            nr = aNr;
        } catch(IOException e) {}
    }

    /**
     * run-Methode fuer Thread
     */
    @Override
    public void run(){
       try {
            byte[] b = new byte[100];
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            String input, statusStr;
            
            in.read(b); 
            bout.write(b);
            input = bout.toString();
            statusStr=Server.empfange(input, nr);
            
            boolean status=true;
            while(status){
                /*in.read(b); 
                bout.write(b);
                input = bout.toString();
                statusStr=Server.empfange(input, nr);
		if (statusStr.equals("-1")) 
                    status=false;   //Empfangen schlug fehl
                */
            }
            clientSocket.close();
	} catch(IOException e) {System.out.println("IO:"+e.getMessage());
        } catch(Exception e) {}
    }
}
